/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.adsi.persistencia;

import com.adsi.modelo.Cuentas;
import com.adsi.modelo.Retiros;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author Estudiante
 */
@Stateless
public class RetirosDAO implements IRetirosDAO {
    
    @PersistenceContext
    private EntityManager entityManager;

    @Override
    public void registrar(Retiros retiros) {
       
        try {
            entityManager.persist(retiros);
        } catch (RuntimeException e) {
        
            throw e;
        }
    }

    @Override
    public List<Retiros> consultar() {
        try {
            String jpql = "select r from Retiros r";
            Query query = entityManager.createQuery(jpql);
            return query.getResultList();
        } catch (RuntimeException c) {
            throw c;
        }
    }

    @Override
    public Retiros consultarPorCod(String numero) {
        try {
            String jpql = "select r from Retiros r where r.Retiros.cue_numero= "+numero;
            Query query = entityManager.createQuery(jpql);
            return entityManager.find(Retiros.class, numero);
        } catch (RuntimeException c) {
            throw c;
        }
    }

   
}
